package infuse;

import util.JDBCUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class TestSqlZhuRu {
    /**
     * 根据id查询代理协议
     * @param id
     */
    public static void selectAgentById(String id){
        Statement statement = null;
        ResultSet resultSet = null;
        Connection connection = null;
        try {
            connection = JDBCUtil.connect();
            statement = connection.createStatement();
            String sql = "select * from agent where id = " + id;
            resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                System.out.println("id:" + resultSet.getObject("id"));
                System.out.println("agent_num:" + resultSet.getObject("agent_num"));
                System.out.println("agent_name:" + resultSet.getObject("agent_name"));
                System.out.println("create_time:" + resultSet.getObject("create_time"));
                System.out.println("---------------------------------------------------------");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            JDBCUtil.closeResource(resultSet, statement, connection);
        }
    }

    public static void main(String[] args) {
        //正常调用
        // TestSqlZhuRu.selectAgentById("1");

        //不正常调用，自定义拼接sql
        TestSqlZhuRu.selectAgentById("1 or 1 = 1");
    }
}
